import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/res/gaps.dart';
import 'package:ls_work/res/styles.dart';
import 'package:ls_work/viewmodel/medical/add_medical_view_model.dart';
import 'package:ls_work/viewmodel/model/combo_data_model.dart';
import 'package:ls_work/widgets/title_value_widget.dart';

class AddMedicalPage extends BaseStatefulMvvmWidget {
  @override
  State<StatefulWidget> createState() => _AddMedicalState();
}

class _AddMedicalState
    extends BaseMvvmState<AddMedicalViewModel, AddMedicalPage> {
  @override
  Widget buildLoadingContentView() {
    return Column(
      children: [
        ListView(
          children: [
            TitleValueWidget(
              "长者姓名",
              hint: "请选择",
              text: viewModel.older?.name ?? "",
            ).onTap(() {
              viewModel.selectOlder();
            }),
            Gaps.line,
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                CommonText("就医原因").setWeight(1),
                CommonInput(
                  hintText: '请输入就医原因',
                  border: InputBorder.none,
                  isDense: true,
                  maxLines: 5,
                  maxLength: 1000,
                  padding: EdgeInsets.zero,
                  keyboardType: CommonInputType.multiline,
                  onChanged: (str){
                    viewModel.medicalReasons = str;
                  },
                ).addToContainer(
                  padding: EdgeInsets.all(6),
                  decoration: BoxDecoration(color: Color(0xfff1f1f1),borderRadius:BorderRadius.circular(8))
                ).setWeight(2)
              ],
            ).addToContainer(
                margin: EdgeInsets.symmetric(horizontal: 16, vertical: 14)),
            TitleValueWidget(
              "病因类型",
              hint: "请选择",
              text: viewModel.medicalCauseTypeName ?? "",
            ).onTap(() {
              viewModel.selectBaseData(ComboDataModel.diseaseReason);
            }),
            Gaps.line,
            TitleValueWidget(
              "就医形式",
              hint: "请选择",
              text: viewModel.medicalTreatmentTypeName ?? "",
            ).onTap(() {
              viewModel.selectBaseData(ComboDataModel.medicalWay);
            }),
            Gaps.line,
            TitleValueWidget(
              "就医时间",
              hint: "请选择",
              text: viewModel.medicalTimeTypeName ?? "",
            ).onTap(() {
              viewModel.selectBaseData(ComboDataModel.medicalTimeType);
            }),
            Gaps.line,
            TitleValueWidget(
              "就医计划",
              hint: "请选择",
              text: viewModel.medicalPlanName ?? "",
            ).onTap(() {
              viewModel.selectBaseData(ComboDataModel.medicalPlan);
            }),
            Gaps.line,
            TitleValueWidget(
              "离开机构时间",
              hint: "请选择",
              text: viewModel.leaveTime ?? "",
            ).onTap(() {
              viewModel.selectLeaveTime();
            }),
            Gaps.line,
            TitleValueWidget(
              "返回机构时间",
              hint: "请选择",
              text: viewModel.backTime ?? "",
            ).onTap(() {
              viewModel.selectBackTime();
            }),
          ],
        ).setWeight(1),

        ElevatedButton(
          onPressed: () {
            viewModel.submitMedical();
          },
          child: CommonText('提交', textSize: 17, textColor: Colors.white),
          style: ButtonStyles.submit_btn_style,
        ).addToContainer(
            margin: EdgeInsets.only(left: 16, right: 16, bottom: 16))
      ],
    );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      appBar: AppBar(
        title: Text('新增就医信息'),
      ),
      body: loadingContentWidget,
    );
  }

  @override
  AddMedicalViewModel createViewModel() {
    return AddMedicalViewModel(context);
  }

  @override
  void onRetryClick() {
    // TODO: implement onRetryClick
  }
}
